home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
003
/
dualsort.arc
/
CALLS20.BAS
next >
Wrap
BASIC Source File
|
1987-08-15
|
3KB
|
104 lines
' Demo program to show how to sort on two fields at one pass.
' This is an extract from a PCB 12.0 utility I am working on.
' Warren Lauzon, SYSOP, Phoenix Techline, 602 936 3058
' EVI 2496, 1200-9600 baud
common shared Linenumber!, logst$, filesize!, dnlds%, filename$, lastdate$
common shared filename$(1)
dim filename$(5000)
CONST true = -1, ok = -1, done = -1
defint a-z
' You will have to change this portion to the actual path & filename
' on your system. It uses the caller file, gets all the downloaded
' file names, sorts them by date and then by name. This is a portion
' of a utility I am working on. The sort fields are arbitrary, done
' only for illustration of how to sort on two fields.
callfile$ = command$
if callfile$ = "" then callfile$ = "c:\basic\caller"
open callfile$ FOR random as #1 len = 64
'open "c:\basic\file$.dat" FOR append as #2
filesize! = LOF(1)/64
REM $INCLUDE: 'frame.bas'
starttime! = timer ' for test purposes only
color 10,7
call frame (10, 70, 5, 20)
call frame (12, 68, 6, 19)
FOR Linenumber! = 1 to filesize!
get #1, Linenumber!
line input #1, logst$
if instr(logst$, ":") = 3 then
lastdate$ = mid$(logst$, 8, 8)
end if
if instr(logst$, "[D]") then
if instr(logst$, "Completed") then call dnlds
end if
st$ = str$(linenumber!)
call xqprintd(st$, 11, 37, 110, 0)
next Linenumber!
sub dnlds static ' gets name and fills it out to 20 spaces, adds date
filename$(dnlds%) = mid$(logst$, (instr(logst$, "[D] " ) + 4), (instr(logst$, "Comp") -12))
pad$ = space$(20)
lset pad$ = filename$(dnlds%)
filename$(dnlds%) = pad$ + lastdate$
dnlds% = dnlds% + 1
END sub
call sort(filename$()) ' call the sort with one parameter
cls
for i = 0 to dnlds%
if left$(filename$(i),12) <> left$(filename$(i+1), 12) then
print filename$(i)
end if
next i
endtime! = timer
locate 12, 36
print using "###.##"; endtime! - starttime!
END
SUB sort (name$(1)) static 'shellsort routine
length% = dnlds%
jump% = 1
WHILE jump% <= length%
jump% = jump% * 2
WEND
' note that it must be swapped once on one field, then
' only swapped again if the first fields are equal, other-
' wise you can get into an endless loop of continual swapping.
WHILE jump% > 1
jump% = (jump% -1) \ 2
finished% = false%
WHILE not finished%
finished% = true%
FOR upper% = 1 to length% - jump%
lower% = upper% + jump%
if mid$(name$(upper%),21,8) < mid$(name$(lower%),21,8) then
swap name$(upper%), name$(lower%) ' first swap
end if
if mid$(name$(upper%),21,8) = mid$(name$(lower%),21,8) _
and mid$(name$(upper%),1,12) > mid$(name$(lower%),1,12) then
swap name$(upper%), name$(lower%) 'second swap
finished% = false%
end if
next upper%
WEND
WEND
END SUB